package com.yksj.healthtalk.adapter;

import java.util.ArrayList;
import java.util.List;

import org.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.drawable.LevelListDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yksj.healthtalk.adapter.SalonAdapter.onClickSalonHeadListener;
import com.yksj.healthtalk.entity.GroupInfoEntity;
import com.yksj.healthtalk.ui.R;

/**
 * 医生控制台群聊
 * @author zhao
 *
 */
public class DoctorStationGroupListAdapter extends BaseAdapter {
	public final List<GroupInfoEntity> mGroupInfoEntities = new ArrayList<GroupInfoEntity>();
	final LayoutInflater mInflater;
	final ImageLoader mImageLoader;
	private Context context;
	
	public DoctorStationGroupListAdapter(List<GroupInfoEntity> list,LayoutInflater inflater,Context context) {
		this.mImageLoader = ImageLoader.getInstance();
		if(list != null)this.mGroupInfoEntities.addAll(list);
		this.mInflater = inflater;
		this.context = context;
	}
	@Override
	public int getCount() {
		return mGroupInfoEntities.size();
	}

	@Override
	public GroupInfoEntity getItem(int position) {
		return mGroupInfoEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder viewHolder;
		if(convertView == null){
			viewHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.grouplist_item1,null);
			viewHolder.headerImageV = (ImageView)convertView.findViewById(R.id.head_image);
			viewHolder.mesgTextV = (TextView)convertView.findViewById(R.id.item_dele);
			viewHolder.nameTextV = (TextView)convertView.findViewById(R.id.name);
			viewHolder.sexImageV = (ImageView)convertView.findViewById(R.id.doctor_salon);
			viewHolder.levelImageV = (ImageView)convertView.findViewById(R.id.levl);
			viewHolder.noteTextV = (TextView)convertView.findViewById(R.id.note);
			viewHolder.monyImageV = (ImageView)convertView.findViewById(R.id.money);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder)convertView.getTag();
		}
		GroupInfoEntity entity = getItem(position);
		viewHolder.nameTextV.setText(entity.getName());
		viewHolder.noteTextV.setText(entity.getDescription());
		LevelListDrawable levelListDrawable = (LevelListDrawable)viewHolder.levelImageV.getDrawable();
		levelListDrawable.setLevel(Integer.valueOf(entity.getGroupLevel()));
		viewHolder.sexImageV.setVisibility(entity.isSalon() ? View.VISIBLE:View.INVISIBLE);
		viewHolder.monyImageV.setVisibility(entity.isCharge()?View.VISIBLE:View.INVISIBLE);
		mImageLoader.displayImage("4",entity.getNormalHeadIcon(),viewHolder.headerImageV);
		viewHolder.headerImageV.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (context instanceof onClickSalonHeadListener) {
					((onClickSalonHeadListener) context).onSalonHeadClick(null, mGroupInfoEntities.get(position), position);
				}
			}
		});
		return convertView;
	}
	
	static class ViewHolder{
		ImageView headerImageV;
		TextView mesgTextV;
		TextView nameTextV;
		ImageView sexImageV;
		ImageView levelImageV;
		ImageView monyImageV;
		TextView noteTextV;
	}
}

